<?php

define('IN_ECS',true);

require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH. '/includes/lib_order.php');

if($_REQUEST['act'] == '')
{
	$smarty->assign('shop_url',urlencode($ecs->url()));
	$smarty->display('index.html');
}
elseif($_REQUEST['act'] == 'top')
{
	$lst = array();
	$nav = $db->getOne('SELECT nav_list FROM ' . $ecs->table('admin_user') . " WHERE user_id = '" . $_SESSION['admin_id'] . "'");
	if(!empty($nav))
	{
		$arr = explode(',', $nav);
		
		foreach($arr as $val)
		{
			$tmp = explode('|', $val);
			$lst[$tmp[1]] = $tmp[0];
		}
	}
	
	$smarty->assign('send_mail_on',$_CFG['send_mail_on']);
	$smarty->assign('nav_list',$lst);
	$smarty->assign('admin_id',$_SESSION['admin_id']);
	$smarty->assign('certi',$_CFG['certi']);
	
	$smarty->display('top.html');
	
}
elseif($_REQUEST['act'] == 'calculator')
{
	$smarty->display('calculator.htm');
}
elseif($_REQUEST['act'] == 'menu')
{
	include_once 'includes/inc_menu.php';
	
	include_once 'includes/inc_priv.php';
	
	foreach($modules as $key=>$value)
	{
		ksort($moduels[$key]);
	}
	
	ksort($modules);
	
	foreach($modules as $key=>$val)
	{
		$menus[$key]['label'] = $_LANG[$key];
		if(is_array($val))
		{
			foreach($val as $k=>$v)
			{
				if(isset($purview[$k]))
				{
					if(is_array($purview[$k]))
					{
						$boole = false;
						foreach($purview[$k] as $action)
						{
							$boole = $boole || admin_priv($action,'',false);
						}
						if(!$boole)
						{
							continue;
						}
					}
					else 
					{
						if(!admin_priv($purview[$k],'',FALSE))
						{
							continue;
						}
					}
				}
				
				if($k == 'ucenter_setup' && $_CFG['integrate_code'] != 'ucenter')
				{
					continue;
				}
				
				$menus[$key]['children'][$k]['label'] = $_LANG[$k];
				$menus[$key]['children'][$k]['action'] = $v;
			}
		}
		else 
		{
			$menus[$key]['action'] = $val;
		}
		
		if(empty($menus[$key]['children']))
		{
			unset($menus[$key]);
		}
	}
	
	$smarty->assign('menus',$menus);
	$smarty->assign('no_help',$_LANG['no_help']);
	$smarty->assign('help_lang',$_CFG['lang']);
	$smarty->assign('admin_id',$_SESSION['admin_id']);
	$smarty->assign('charset',EC_CHARSET);
	
	$smarty->display('menu.html');
	
}
elseif($_REQUEST['act'] == 'clear_chache')
{
	
}
elseif($_REQUEST['act'] == 'main')
{
	if(isset($_SESSION['shop_guide']) && $_SESSION['shop_guide'] === true)
	{
		unset($_SESSION['shop_guide']);
		ecs_header("Location:./index.php?act=first\n");
		
		exit();
	}
	
	$gd = gd_version();
	
	$warning = array();
	
	if($_CFG['shop_closed'])
	{
		$warning[] = $_LANG['shop_closed_tips'];
	}
	
	if(file_exists('../install'))
	{
		$warning[] = $_LANG['remove_install'];
	}
	
	if(file_exists('../upgrade'))
	{
		$warning[] = $LANG['remove_upgrade'];
	}
	
	if(file_exists('../demo'))
	{
		$warning[] = $_LANG['remove_demo'];
	}
	
	$open_basedir = ini_get('open_basedir');
	if(!empty($open_basedir))
	{
		$open_basedir = str_replace(array("\\","\\\\"), array("/","/"), $open_basedir);
		
	}
	
	clearstatcache();
	
	$smarty->assign('warning_arr',$warning);

	$today = local_getdate();
	$sql = 'SELECT COUNT(*) FROM ' .$ecs->table('stats') .
			' WHERE access_time > ' . (mktime(0,0,0,$today['mon'],$today['mday'],$today['year']) - date('Z'));
	
	$today_visit = $db->getOne($sql);
	$smarty->assign('today_visit',$today_visit);
	
	$online_users = $sess->get_users_count();
	$smarty->assign('online_users',$online_users);
	
	$smarty->assign('ecs_version', VERSION);
	$smarty->assign('ecs_release', RELEASE);
	$smarty->assign('ecs_charset',strtoupper(EC_CHARSET));
	
	$smarty->display('start.html');
	
}
elseif($_REQUEST['act'] == 'main_api')
{
	
}
elseif($_REQUEST['act'] == 'first')
{
	
}
elseif($_REQUEST['act'] == 'second')
{
	
}
elseif($_REQUEST['act'] == 'third')
{
	
}
elseif($_REQUEST['act'] == 'about_us')
{
	
}
elseif($_REQUEST['act'] == 'drag')
{
	
}
elseif($_REQUEST['act'] == 'check_order')
{
	
}
